package com.ctmy.web.controller.system;

import com.baomidou.mybatisplus.plugins.Page;
import com.ctmy.framework.web.BaseController;
import com.ctmy.system.domain.SysUser;
import com.ctmy.system.mapper.SysUserMapper;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 登录验证
 * 
 * @author zhoujw110
 */
@Controller
@RequestMapping("/sys/")
public class SysController extends BaseController {

    @Autowired
    private SysUserMapper sysUserMapper;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    public Object list() {
        List<SysUser> list = sysUserMapper.selectAll(new Page<SysUser>(1,10));
        return success(list);
    }

    @RequestMapping(value = "/listPage",method = RequestMethod.GET)
    @ResponseBody
    public Object listPage() {
        List<SysUser> list = sysUserMapper.selectAll(new Page<SysUser>(1,10));

        Page<SysUser> pageList = new Page(1,10);
        pageList.setRecords(list);

        Map result = Maps.newHashMap();
        result.put("listPage",pageList);
        result.put("list",list);

        return success(result);
    }


    @RequestMapping(value = "/user/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Object findId(@PathVariable(value = "id") String id) {
        SysUser user = sysUserMapper.selectById(id);
        return  user == null ? error():success(user);
    }
}
